		
// create angular app
			var validationApp = angular.module(' ', []);
			// create angular controller
			validationApp.controller('mainForm', function($scope,$http) {
				// function to submit the form after all validation has occurred			
				$scope.ValidateRegistration = function(isValid) 
				{
					$scope.registrtion="registration";
					// check to make sure the form is completely valid
		            if (isValid){
						$http.post("registration", {
							"Username": $scope.Username,"Password":$scope.Password,
							"Nickname": $scope.Nickname ,"Email": $scope.Email,
							"Photo": $scope.Photo,"Description":$scope.Description,"type":$scope.registrtion,
		                            
		                        }).then(function(response) {
		                        	
		                        	if (response.data == "Failed")
	                        		{
		                        		$scope.errLabel="Username,Nickname or Email are incorrect";
		                        		
	                        		}
		                        	else
		                        	{
		                        		window.location = response.data;
		                        		
		                        	}
		                        	
	                        		
		                        });
	                	
		            }    

				};
				$scope.CountsWord = function()
				{
					if ( $scope.Description == null) // if it is empty - for the begining 
						return false;
					
					var tempArray = $scope.Description.split(/\s+/);
					
					$scope.n = tempArray.length;
					
					if (   tempArray.length > 50)
						return true;
					
					return false ;
				}
				$scope.ValidateLogin = function(isValid)
				{	
					$scope.Login="Login";
					if (isValid)
					{
						$http.post("registration", {
							"Username": $scope.Username,"Password":$scope.Password,
							"type":$scope.Login,
		                        }).then(function(response) {
		                        	if (response.data == "Failed")
		                        	{
		                        		$scope.errLabel="Username or Password incorrect";
		                        		
		                        	}
		                        	
		                        	else
	                        		{
		                        		window.location = response.data;
	                        		}
	                        		
		                        });
						
					}
				
				};
					
				$scope.checkSessionFromLogin = function()
				{

					$http.post("sessioncheck", {Type:"loginWindow"}).then(function(response) {
	                	if (response.data.Answer == "Success" )
	            		{
	                		window.location = response.data.Location;
	            		}
	                	
	                });
					
				};	
				
			});
			
			
			
			